package com.woniuxy.jdkproxy;

import com.woniuxy.aspect.Aspect;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyProxy {
    public static Object createProxyObject(Object obj) {
        Object o = Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(),
                (Object proxy, Method method, Object[] args) -> {
                    //前置任务
                    new Aspect().log();
                    Object invoke = method.invoke(obj, args);
                    //后置任务
                    new Aspect().commitTransation();
                    return invoke;
                });
        return o;
    }
}
